package com.shanhesoft.java.modules.exam.enums;

import com.shanhesoft.java.common.persistence.service.DataService;
import com.shanhesoft.java.modules.exam.domain.OjProblems;
import com.shanhesoft.java.modules.exam.service.*;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 题目类型枚举
 *
 * @author tangyi
 * @date 2019/6/16 16:22
 */
@Getter
@AllArgsConstructor
public enum SubjectTypeEnum {

	CHOICES("选择题", 0, TBankSingleChoiceQueService.class),

	MULTIPLE_CHOICES("多选题", 1, TBankMultipleChoiceQueService.class),

	JUDGEMENT("判断题", 2, TBankJudgeQueService.class),

	SHORT_ANSWER("简答题", 3, TBankFillQueService.class),

	PROBLEMS_ANSWER("编程题", 4, OjProblemsService.class);

	private String name;

	private Integer value;

	private Class<? extends DataService> service;

	/**
	 * 根据类型返回具体的SubjectType
	 *
	 * @param value value
	 * @return SubjectType
	 */
	public static SubjectTypeEnum matchByValue(Integer value) {
		for (SubjectTypeEnum item : SubjectTypeEnum.values()) {
			if (item.value.equals(value)) {
				return item;
			}
		}
		return CHOICES;
	}

	/**
	 * 根据描述返回具体的SubjectType
	 *
	 * @param name name
	 * @return SubjectType
	 */
	public static SubjectTypeEnum matchByName(String name) {
		for (SubjectTypeEnum item : SubjectTypeEnum.values()) {
			if (item.name.equals(name)) {
				return item;
			}
		}
		return CHOICES;
	}
}
